#include <iostream>
#include <thread>
#include <memory>
#include <cstdlib>
#include <unistd.h>
#include "ringQueue.hpp"
using namespace std;

void Product(RingQueue<int>* rq_ptr, int i)
{
    while(true)
    {
        int t = rand() % 100;
        rq_ptr->Push(t);
        cout << "线程" << i << "生产者生产了一个数据：" << t << endl;
        sleep(1);
    }
}

void Consume(RingQueue<int>* rq_ptr, int i)
{
    while(true)
    {
        int t = 0;
        rq_ptr->Pop(&t);
        cout << "线程" << i << "消费者消费了一个数据：" << t << endl;
        sleep(1);
    }
}
int main()
{
    srand(time(nullptr));
    RingQueue<int>* rq_ptr = new RingQueue<int>();
    vector<thread> pro_threads;
    vector<thread> com_threads;
    mutex mtx;
    for(int i = 0; i < 3; i++)
    {
        pro_threads.push_back(thread(Product, rq_ptr, i + 1));
    }
    for(int i = 0; i < 3; i++)
    {
        com_threads.push_back(thread(Consume, rq_ptr, i + 1));
    }
    for(auto& t : pro_threads)  t.join();
    for(auto& t : com_threads)  t.join();
    return 0;
}